﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CallSignAnalysis
{
    public partial class FmConfirmInfo : Form
    {
        /// <summary>
        /// 返回的字符串
        /// </summary>
        public string ReturnedModeString { get; private set; }

        public FmConfirmInfo()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;
        }
        /// <summary>
        /// 递归方法,获取指定controlName的控件;如果控件未找到,则返回null,请注意判断null
        /// </summary>
        /// <param name="container">容器控件,可以是窗体form,也可以是panel,GroupBox等</param>
        /// <param name="controlName">控件名称</param>
        /// <returns>返回一个控件类型</returns>
        private Control getControlFromName(Control container)
        {
            foreach (Control c in container.Controls)
            {
                if (c is Sunny.UI.UIButton || c is Sunny.UI.UICheckBox || c is Sunny.UI.UILabel || c is Button || c is Sunny.UI.UIGroupBox)
                {
                    string t = RWini.ReadValue(c.Name, "Text");
                    if (!string.IsNullOrWhiteSpace(t))
                    {
                        c.Text = t;
                        string name = RWini.ReadValue(c.Name, "Font");
                        int size = RWini.ReadInt(c.Name, "Size", 16);
                        string Sizes = RWini.ReadValue(c.Name, "Size");
                        int.TryParse(Sizes, out size);
                        if (!string.IsNullOrWhiteSpace(name))
                        {
                            FontFamily ff = new FontFamily(name);
                            FontStyle style = FontStyle.Bold;
                            // style |= FontStyle.Regular;
                            // style |= FontStyle.Italic;, GraphicsUnit.World
                            c.Font = new Font(ff, size, style);
                        }

                    }
                }
                if (c.HasChildren)
                {
                    //这里不能直接写return  getControlFromName(c, controlName);因为会导致只执行第一个子容器控件,如果未找到就提前返回了Null;
                    Control myControl = getControlFromName(c);
                    if (myControl != null)
                    {
                        return myControl;
                    }
                }
            }
            //并非所有的代码路径都返回值,未找到就返回null
            return null;
        }

        private void FmConfirmInfo_Load(object sender, EventArgs e)
        {
            RWini.SetPath(g.lang + ".ini");
            getControlFromName(this);
        }

        private void smr_confirm_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK; // 设置窗口的DialogResult为OK
            this.Close(); // 关闭窗口
        }

        private void smr_close_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel; // 设置窗口的DialogResult为Cancel
            this.Close(); // 关闭窗口
        }

        private void rbtn_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtn_cw.Checked)
            {
                ReturnedModeString = rbtn_cw.Text;
            }
            if (rbtn_pkt.Checked)
            {
                ReturnedModeString = rbtn_pkt.Text;
            }
            if (rbtn_ssb.Checked)
            {
                ReturnedModeString = rbtn_ssb.Text;
            }
            if (rbtn_ft4.Checked)
            {
                ReturnedModeString = rbtn_ft4.Text;
            }
        }
    }
}
